package utn.tsb.tsbxml;

import com.trolltech.qt.gui.QTreeWidget;
import com.trolltech.qt.gui.QTreeWidgetItem;
import java.util.HashMap;
import java.util.Set;


public class TreeNode extends QTreeWidgetItem{

    private String value;
    private HashMap<String, String> attributes;

    public TreeNode(QTreeWidgetItem parent){
        super(parent);
        value = "";
        attributes = new HashMap<String, String>();
    }

    public TreeNode(QTreeWidget parent){
        super(parent);
        value = "";
        attributes = new HashMap<String, String>();
    }

    public void createTooltip(){
        StringBuilder tooltip = new StringBuilder();
        tooltip.append("Name: " + this.text(0) + "\n");
        tooltip.append("Value: " + this.value + "\n");
        tooltip.append("Attributes:\n");
        Set<String> keys = this.attributes.keySet();
        String[] array = keys.toArray(new String[0]);
        for(int i = 0; i < array.length; i++){
            String att = array[i] + ": " + this.attributes.get(array[i]);
            tooltip.append(att + "\n");
        }

        this.setToolTip(0, tooltip.toString());
    }

    /**
     * @return the value
     */
    public String getValue() {
        return value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(String value) {
        this.value = value;
    }

    /**
     * @return the attributes
     */
    public HashMap<String, String> getAttributes() {
        return attributes;
    }

    /**
     * @param attributes the attributes to set
     */
    public void setAttributes(HashMap<String, String> attributes) {
        this.attributes = attributes;
    }

}
